//
//  LandView.m
//  豆瓣终极版
//
//  Created by dllo on 15/12/19.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LandView.h"

@interface LandView ()

@property (nonatomic, retain) UILabel *userNameLab;
@property (nonatomic, retain) UILabel *keyLab;
@property (nonatomic, retain) UIButton *landingButton;
@property (nonatomic, retain) UIButton *RegisterButton;


@end

@implementation LandView

- (void)dealloc{
    [_landingButton release];
    [_RegisterButton release];
    [_userNameTextField release];
    [_keyTextField release];
    [_userNameLab release];
    [_keyLab release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createLandViews];
    }
    return self;
}

- (void)createLandViews{
    // 添加用户名lab
    self.userNameLab = [[UILabel alloc] initWithFrame:CGRectMake(30, 120, 200, 40)];
    self.userNameLab.text = @"用户名:";
    self.userNameLab.font = [UIFont systemFontOfSize:22];
    [self addSubview:self.userNameLab];
    [_userNameLab release];
    
    // 添加密码lab
    self.keyLab = [[UILabel alloc] initWithFrame:CGRectMake(30, 180, 200, 40)];
    self.keyLab.text = @"密码:";
    self.keyLab.font = [UIFont systemFontOfSize:22];
    [self addSubview:self.keyLab];
    [_keyLab release];
    
    self.userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 120, 200, 40)];
    self.userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.userNameTextField.placeholder = @"请输入用户名";
    [self addSubview:self.userNameTextField];
    [_userNameTextField release];
    
    self.keyTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 180, 200, 40)];
    self.keyTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.keyTextField.placeholder = @"请输入密码";
    self.keyTextField.secureTextEntry = YES;
    [self addSubview:self.keyTextField];
    [_keyTextField release];
    
    self.landingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.landingButton.frame = CGRectMake(30, 270, 140, 40);
    [self.landingButton setImage:[UIImage imageNamed:@"login_button.png"] forState:UIControlStateNormal];
    [self.landingButton addTarget:self action:@selector(landingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.landingButton];
    [_landingButton release];
    
    self.RegisterButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.RegisterButton.frame = CGRectMake(180, 270, 140, 40);
    [self.RegisterButton setImage:[UIImage imageNamed:@"register_button.png"] forState:UIControlStateNormal];
    [self addSubview:self.RegisterButton];
    [_RegisterButton release];
    [self.RegisterButton addTarget:self action:@selector(registerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
   
}
// 点击登陆按钮触发事件
- (void)landingButtonAction:(UIButton *)landingBtn{
    [self.landDelegate passByValueToLandPageVCUserName:self.userNameTextField.text key:self.keyTextField.text];
    
}

// 点击注册按钮触发事件
- (void)registerButtonAction:(UIButton *)registerBtn{
    [self.landDelegate letLandPageViewPushToRegisterView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_userNameTextField resignFirstResponder];
    [_keyTextField resignFirstResponder];
    
}

@end
